﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;

namespace MyDemos.Classes
{
    public class RssParseUtil
    {


        private List<RssContent> mContnetList = new List<RssContent> ();


        public RssParseUtil (String pContent)
        {
            Regex _Regexp = new Regex ("●", RegexOptions.Multiline);

            String[] _Items = _Regexp.Split (pContent);

            List<String> _List = _Items.ToList ();
            _List.RemoveAt (0);
            MatchCollection collection = _Regexp.Matches (pContent);

            Regex _Regexp2 = new Regex ("<(\\S*?)[^>]*>.*?</\\1>|<.*? />", RegexOptions.Multiline);
            Regex _Regexp3 = new Regex ("\\(\\)\n?", RegexOptions.Multiline);
            Regex _Regexp4 = new Regex ("\"htt.*?\"", RegexOptions.Multiline);
            Regex _Regexp5 = new Regex (".{8}.*?[\\s，。]{1}", RegexOptions.Multiline);

            for (int i = 0; i < _List.Count; i++)
            {
                String _Title = _Regexp5.Match (_List[i]).Value;

                String _Web = _Regexp2.Match (_List[i]).Value;
                int _Index = _Web.IndexOf ("http");
                int _Index2 = _Web.IndexOf ("\"", _Index);

                String _Web2 = _Web.Substring (_Index, _Index2 - _Index);
                _List[i] = _Regexp2.Replace (_List[i], "");

                mContnetList.Add (new RssContent
                {
                    Title = _Title,
                    WebSite = _Web2,
                    Content = _Regexp3.Replace (_List[i], "")
                });
            }


        }

        public List<RssContent> GetRssList ()
        {
            return mContnetList;
        }
    }
}
